import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:life_service/views/customer/controller.dart';
import 'package:life_service/views/home/controller.dart';
import 'package:life_service/views/home/index.dart' deferred as home_index;
import 'package:life_service/views/hotel/controller.dart';
import 'package:life_service/views/hotel/list.dart' deferred as hotel_list;
import 'package:life_service/views/hotel/main.dart' deferred as hotel_main;
import 'package:life_service/views/hotel/info.dart' deferred as hotel_info;
import 'package:life_service/views/hotel/comment.dart'
    deferred as hotel_comment;
import 'package:life_service/views/hotel/order.dart' deferred as hotel_order;
import 'package:life_service/views/hotel/pay.dart' deferred as hotel_pay;
import 'package:life_service/views/hotel/success.dart'
    deferred as hotel_success;
import 'package:life_service/views/mine/controller.dart';
import 'package:life_service/views/mine/evaluate.dart'
    deferred as mine_evaluate;
import 'package:life_service/views/mine/coupons.dart' deferred as mine_coupons;
import 'package:life_service/views/mine/used/info.dart'
    deferred as mine_used_info;
import 'package:life_service/views/mine/used/add.dart'
    deferred as mine_used_add;
import 'package:life_service/views/mine/wallet/bill.dart'
    deferred as mine_wallet_bill;
import 'package:life_service/views/mine/wallet/recharge.dart'
    deferred as mine_wallet_recharge;
import 'package:life_service/views/mine/wallet/complete.dart'
    deferred as mine_wallet_complete;
import 'package:life_service/views/mine/wallet/card.dart'
deferred as mine_wallet_card;
import 'package:life_service/views/mine/member/center.dart'
    deferred as mine_member_center;
import 'package:life_service/views/mine/order/list.dart'
    deferred as mine_order_list;
import 'package:life_service/views/search/address.dart'
    deferred as search_address;
import 'package:life_service/views/search/controller.dart';
import 'package:life_service/views/select/city.dart' deferred as select_city;
import 'package:life_service/views/select/controller.dart';
import 'package:life_service/views/select/date.dart' deferred as select_date;
import 'package:life_service/views/customer/chat.dart'
    deferred as customer_chat;

class Routes {
  Routes._();

  static const String home = '/';

  static const String selectDate = '/select/date';

  static const String selectCity = '/select/city';

  static const String searchAddress = '/search/address';

  static const String hotelList = '/hotel/list';

  static const String hotelMain = '/hotel/main';

  static const String hotelInfo = '/hotel/info';

  static const String hotelComment = '/hotel/comment';

  static const String hotelOrder = '/hotel/order';

  static const String hotelPay = '/hotel/pay';

  static const String hotelSuccess = '/hotel/success';

  static const String customerChat = '/customer/chat';

  static const String mineEvaluate = '/mine/evaluate';

  static const String mineCoupons = '/mine/coupons';

  static const String mineUsedInfo = '/mine/used/info';

  static const String mineUsedAdd = '/mine/used/add';

  static const String mineWalletBill = '/mine/wallet/bill';

  static const String mineWalletCard = '/mine/wallet/card';

  static const String mineWalletRecharge = '/mine/wallet/recharge';

  static const String mineWalletComplete = '/mine/wallet/complete';

  static const String mineMemberCenter = '/mine/member/center';

  static const String mineOrderList = '/mine/order/list';

  static final List<GetPage> pages = [
    GetPage(
      title: '首页',
      name: home,
      page: () {
        return AsyncRouterPage(home_index.loadLibrary(), (_) {
          return home_index.HomePage();
        });
      },
      binding: BindingsBuilder.put(() => HomeController()),
    ),
    GetPage(
      title: '选择日期',
      name: selectDate,
      page: () {
        return AsyncRouterPage(select_date.loadLibrary(), (_) {
          return select_date.SelectDatePage();
        });
      },
      binding: BindingsBuilder.put(() => SelectDateController()),
    ),
    GetPage(
      title: '选择城市',
      name: selectCity,
      page: () {
        return AsyncRouterPage(select_city.loadLibrary(), (_) {
          return select_city.SelectCityPage();
        });
      },
      binding: BindingsBuilder.put(() => SelectCityController()),
    ),
    GetPage(
      title: '搜索',
      name: searchAddress,
      page: () {
        return AsyncRouterPage(search_address.loadLibrary(), (_) {
          return search_address.SearchAddressPage();
        });
      },
      binding: BindingsBuilder.put(() => SearchAddressController()),
    ),
    GetPage(
      title: '酒店列表',
      name: hotelList,
      page: () {
        return AsyncRouterPage(hotel_list.loadLibrary(), (_) {
          return hotel_list.HotelListPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelListController()),
    ),
    GetPage(
      title: '酒店主页',
      name: hotelMain,
      page: () {
        return AsyncRouterPage(hotel_main.loadLibrary(), (_) {
          return hotel_main.HotelMainPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelMainController()),
    ),
    GetPage(
      title: '酒店详情',
      name: hotelInfo,
      page: () {
        return AsyncRouterPage(hotel_info.loadLibrary(), (_) {
          return hotel_info.HotelInfoPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelInfoController()),
    ),
    GetPage(
      title: '酒店评论',
      name: hotelComment,
      page: () {
        return AsyncRouterPage(hotel_comment.loadLibrary(), (_) {
          return hotel_comment.HotelCommentPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelCommentController()),
    ),
    GetPage(
      title: '酒店订单',
      name: hotelOrder,
      page: () {
        return AsyncRouterPage(hotel_order.loadLibrary(), (_) {
          return hotel_order.HotelOrderPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelOrderController()),
    ),
    GetPage(
      title: '提交酒店订单',
      name: hotelPay,
      page: () {
        return AsyncRouterPage(hotel_pay.loadLibrary(), (_) {
          return hotel_pay.HotelPayPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelPayController()),
    ),
    GetPage(
      title: '酒店订单支付',
      name: hotelSuccess,
      page: () {
        return AsyncRouterPage(hotel_success.loadLibrary(), (_) {
          return hotel_success.HotelSuccessPage();
        });
      },
      binding: BindingsBuilder.put(() => HotelSuccessController()),
    ),
    GetPage(
      title: '客服',
      name: customerChat,
      page: () {
        return AsyncRouterPage(customer_chat.loadLibrary(), (_) {
          return customer_chat.CustomerChatPage();
        });
      },
      binding: BindingsBuilder.put(() => CustomerChatController()),
    ),
    GetPage(
      title: '我的评价',
      name: mineEvaluate,
      page: () {
        return AsyncRouterPage(mine_evaluate.loadLibrary(), (_) {
          return mine_evaluate.MineEvaluatePage();
        });
      },
      binding: BindingsBuilder.put(() => MineEvaluateController()),
    ),
    GetPage(
      title: '领取中心',
      name: mineCoupons,
      page: () {
        return AsyncRouterPage(mine_coupons.loadLibrary(), (_) {
          return mine_coupons.MineCouponsPage();
        });
      },
      binding: BindingsBuilder.put(() => MineCouponsController()),
    ),
    GetPage(
      title: '常用信息',
      name: mineUsedInfo,
      page: () {
        return AsyncRouterPage(mine_used_info.loadLibrary(), (_) {
          return mine_used_info.MineUsedInfoPage();
        });
      },
      binding: BindingsBuilder.put(() => MineUsedInfoController()),
    ),
    GetPage(
      title: '新增信息',
      name: mineUsedAdd,
      page: () {
        return AsyncRouterPage(mine_used_add.loadLibrary(), (_) {
          return mine_used_add.MineUsedAddPage();
        });
      },
      binding: BindingsBuilder.put(() => MineUsedAddController()),
    ),
    GetPage(
      title: '我的账单',
      name: mineWalletBill,
      page: () {
        return AsyncRouterPage(mine_wallet_bill.loadLibrary(), (_) {
          return mine_wallet_bill.MineWalletBillPage();
        });
      },
      binding: BindingsBuilder.put(() => MineWalletBillController()),
    ),
    GetPage(
      title: '充值',
      name: mineWalletRecharge,
      page: () {
        return AsyncRouterPage(mine_wallet_recharge.loadLibrary(), (_) {
          return mine_wallet_recharge.MineWalletRechargePage();
        });
      },
      binding: BindingsBuilder.put(() => MineWalletRechargeController()),
    ),
    GetPage(
      title: '充值成功',
      name: mineWalletComplete,
      page: () {
        return AsyncRouterPage(mine_wallet_complete.loadLibrary(), (_) {
          return mine_wallet_complete.MineWalletCompletePage();
        });
      },
      binding: BindingsBuilder.put(() => MineWalletCompleteController()),
    ),
    GetPage(
      title: '我的钱包',
      name: mineWalletCard,
      page: () {
        return AsyncRouterPage(mine_wallet_card.loadLibrary(), (_) {
          return mine_wallet_card.MineWalletCardPage();
        });
      },
      binding: BindingsBuilder.put(() => MineWalletCardController()),
    ),
    GetPage(
      title: '会员中心',
      name: mineMemberCenter,
      page: () {
        return AsyncRouterPage(mine_member_center.loadLibrary(), (_) {
          return mine_member_center.MineMemberCenterPage();
        });
      },
      binding: BindingsBuilder.put(() => MineMemberCenterController()),
    ),
    GetPage(
      title: '会订单员中心',
      name: mineOrderList,
      page: () {
        return AsyncRouterPage(mine_order_list.loadLibrary(), (_) {
          return mine_order_list.MineOrderListPage();
        });
      },
      binding: BindingsBuilder.put(() => MineOrderListController()),
    ),
  ];
}

class AsyncRouterPage extends StatelessWidget {
  final Future libraryFuture;

  final WidgetBuilder child;

  const AsyncRouterPage(this.libraryFuture, this.child, {super.key});

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: libraryFuture,
        builder: (c, s) {
          if (s.connectionState == ConnectionState.done) {
            if (s.hasError) {
              return Scaffold(
                appBar: AppBar(),
                body: Container(
                  alignment: Alignment.center,
                  child: Text(
                    'Error: ${s.error}',
                    style: const TextStyle(color: Colors.red),
                  ),
                ),
              );
            }
            return child.call(context);
          }
          return Scaffold(
            appBar: AppBar(),
            body: Container(
              alignment: Alignment.center,
              child: const CircularProgressIndicator(),
            ),
          );
        });
  }
}
